package cn.scw.project.system.controller;

import cn.scw.common.constant.SysConsts;
import cn.scw.framework.aspectj.lang.annotation.Log;
import cn.scw.framework.aspectj.lang.enums.BusinessType;
import cn.scw.framework.web.controller.BaseController;
import cn.scw.framework.web.domain.AjaxResult;
import cn.scw.framework.web.page.TableDataInfo;
import cn.scw.project.system.domain.SysBanner;
import cn.scw.project.system.domain.netework.bean.SysBannerAddReq;
import cn.scw.project.system.service.ISysBannerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * bannerController
 *
 * @author api
 * @date 2020-05-14
 */
@Api(tags = "轮播图管理")
@RestController
@RequestMapping(SysConsts.CONTEXT_PATH + "/system/banner")
public class SysBannerController extends BaseController {

    @Autowired
    private ISysBannerService bannerService;

    @ApiOperation("查询banner列表")
    @GetMapping("/list")
    public TableDataInfo list(@RequestParam(required = false) String like) {
        startPage();
        List<SysBanner> list = bannerService.selectBannerList(like);
        return getDataTable(list);
    }

    @ApiOperation("wx-查询banner列表")
    @GetMapping("/wx/list")
    public TableDataInfo wxList(@RequestParam(required = false) String like) {
        startPage();
        List<SysBanner> list = bannerService.selectBannerList(like);
        return getDataTable(list);
    }

    @ApiOperation("查询banner详情")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(bannerService.selectBannerById(id));
    }

    @ApiOperation("新增banner")
    @Log(title = "banner", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(SysBannerAddReq req) {
        return toAjax(bannerService.insertBanner(req));
    }

    @ApiOperation("修改banner")
    @Log(title = "banner", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(SysBannerAddReq req) {
        return toAjax(bannerService.updateBanner(req));
    }

    @ApiOperation("删除banner")
    @Log(title = "banner", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(bannerService.deleteBannerByIds(ids));
    }
}
